/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reyes.mysite.dao;

import java.util.List;
import reyes.mysite.jdo.Blog;
/**
 *
 * @author reyesyang
 */
public class BlogDAO extends DAO{

    public BlogDAO(){
    };

    public void postBlog(Blog blog){
        try{
            getPM().makePersistent(blog);
        }catch(Exception e){
            System.out.println("Can't post new blog named "+blog.getTitle()+" for reason: "+e.getMessage());
        }
    }

    public List<Blog> getAllBlog(){
        List<Blog> blogs = null;
        try{
            String query = "select from "+ Blog.class.getName();
            blogs = (List<Blog>)getPM().newQuery(query).execute();
        }catch(Exception e){
            System.out.println("Can't get all blogs from date base for reason: "+e.getMessage());
        }
        return blogs;
    }


}
